package net.jueb.marshalling.client;

import net.jueb.marshalling.pojo.Request;
import net.jueb.marshalling.pojo.Response;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class MarshallingClientHandler extends ChannelHandlerAdapter{
	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		Request request=new Request();
		request.setMsg("Hello Server");
		for(int i=1;i<=10;i++)
		{
			request.setId(i);
			ctx.writeAndFlush(request);
		}
	}
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		Response response=(Response)msg;
		if(msg==null)
		{
			return ;
		}
		System.out.println("收到回复："+response.toString());
	}
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}
